package com.qinyi.common.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * @author wangan on 2019/6/3
 * @description 数据源切换处理
 */
public class DynamicDataSourceContextHolder {

	private final static Logger log = LoggerFactory.getLogger(DynamicDataSourceContextHolder.class);


	private final static ThreadLocal<String> CONTEXT_HOLDER = new ThreadLocal<>();

	public static void setDataSourceType(String dataSourceType) {
		log.info("切换到{}数据源", dataSourceType);
		CONTEXT_HOLDER.set(dataSourceType);
	}

	public static String getDataSourceType() {
		return CONTEXT_HOLDER.get();
	}

	public static void clearDataSourceType() {
		CONTEXT_HOLDER.remove();
	}

}
